//
// Created by Win on 2017/1/19.
//
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frbyte_buffer.h"

#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_cunit.h"
#include "apmtest_comm.h"
#include "frhessian.h"

extern int __frhessian_parse_char(Frbyte_Packet *p_st_data, hessian_parse *p_st_parse);

static int __suite_init(void)
{
    
    return 0;
}

static int __suite_cleanup(void)
{
    
    return 0;
}



static void __case1(void)
{
    
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    
    i_ret = __frhessian_parse_char(p_st_data, NULL);
    
    CU_ASSERT_EQUAL(i_ret, -1);
    return;
    
}



static void __case2(void)
{
    
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    hessian_parse st_parst = {FR_NO, -1, 0};
    p_st_data = bytebuff_creat();
    
    bytebuff_add(p_st_data, (char *)"\x53\x00\x02\x31", 4);
    
    i_ret = __frhessian_parse_char(p_st_data, &st_parst);
    
    CU_ASSERT(i_ret > 0);
    bytebuff_free(&p_st_data);
    
    return;
    
}

static void __case3(void)
{
    
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    hessian_parse st_parst = {FR_NO, -1, 0};
    p_st_data = bytebuff_creat();
    
    bytebuff_add(p_st_data, (char *)"\x73\x00\x02\x31", 4);
    
    i_ret = __frhessian_parse_char(p_st_data, &st_parst);
    
    CU_ASSERT(i_ret > 0);
    bytebuff_free(&p_st_data);
    
    return;
    
}

static void __case4(void)
{
    
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    hessian_parse st_parst = {FR_NO, -1, 0};
    p_st_data = bytebuff_creat();
    
    bytebuff_add(p_st_data, (char *)"\x74\x00\x02\x31", 4);
    
    i_ret = __frhessian_parse_char(p_st_data, &st_parst);
    
    CU_ASSERT_EQUAL(i_ret, -1);
    bytebuff_free(&p_st_data);
    
    return;
    
}

int add_suite___frhessian_parse_char(void)
{
    CU_pSuite pSuite = NULL;
    
    if ((pSuite = CU_add_suite("frhessian.c __frhessian_parse_char()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;
    
    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    
    
    return FR_SUCC;
    
}